package com.kaoshi.management.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kaoshi.common.config.Result;
import com.kaoshi.management.pojo.RolePermissionVo;
import com.kaoshi.management.pojo.XtRolePermissions;
import com.kaoshi.management.service.RolePermissionVoService;
import com.kaoshi.management.service.XtRolePermissionsService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2024-11-07
 */
@RestController
@CrossOrigin
@RequestMapping("/xt-role-permissions")
public class XtRolePermissionsController {

    @Autowired
    private XtRolePermissionsService xtRolePermissionsService;

    @Autowired
    private RolePermissionVoService rolePermissionVo;

        @PostMapping("/cc/{current}/{pageSize}")
    public Result findAll(@PathVariable Integer current,
                          @PathVariable Integer pageSize,
                              @RequestBody XtRolePermissions rp) {
            System.out.println(rp.getRoleId());
        Page<RolePermissionVo> pageList = rolePermissionVo.getPageLis(current, pageSize,rp.getRoleId());
        return Result.ok(pageList);
    }
    @PostMapping("/save")
    public Result save(@RequestBody XtRolePermissions xtRolePermissions) {
            //遍历permissionIds
            Integer[] permissionIds =  xtRolePermissions.getPermissionIds();
            for (Integer permissionId : permissionIds) {
                XtRolePermissions rp = new XtRolePermissions();
                rp.setRoleId(xtRolePermissions.getRoleId());
                rp.setPermissionId(permissionId);
                xtRolePermissionsService.save(rp);
            }
            System.out.println("1111111111111111111111111111111111111111111111111"+xtRolePermissions);
            return Result.ok("保存成功");
    }

}
